package net.zjitc.io.bufferedstream;

import java.io.*;


/**
 * @Author admin
 * @Date 2019/4/10 10:16
 */
public class CopyImage {
    public static void main(String[] args) {
        InputStream in=null;
        BufferedInputStream bis =null;
        OutputStream out=null;
        BufferedOutputStream bos=null;
        try {
            in=new FileInputStream("D:\\Kaola.jpg");
            bis=new BufferedInputStream(in);
            out=new FileOutputStream("2.jpg");
            bos=new BufferedOutputStream(out);
            int len =0;
            byte[] bytes=new byte[1024];
            while ((len=bis.read(bytes))!=-1) {
                bos.write(bytes,0,len);
            }
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (out!=null){
                try {
                   out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bos!=null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bis!=null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
